/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.datalogic.define;

import com.openbravo.data.loader.table.I_TableSentenceBuilder;
import e.odbo.data.dao.EntityManager;
import e.odbo.data.dao.I_ParentNode;
import e.odbo.data.bean.IKeyed;
import cn.ekuma.epos.bean.util.StateObjectHelper;
import cn.ekuma.epos.datalogic.I_CustomerDebtProcesser;
import cn.ekuma.epos.datalogic.I_DataLogicERP;
import cn.ekuma.epos.datalogic.I_ProductRecommend;
import cn.ekuma.epos.datalogic.businesslogic.orderprocess.I_ProcessManager;
import cn.ekuma.epos.datalogic.define.dao.ProductReserveDAO;
import cn.ekuma.epos.datalogic.define.dao.ProductStockLevelDAO;
import cn.ekuma.epos.datalogic.define.dao.ServingDAO;
import cn.ekuma.epos.datalogic.define.dao.SharedProductDAO;
import cn.ekuma.epos.datalogic.define.dao.crm.CustomerAddressDAO;
import cn.ekuma.epos.datalogic.define.dao.crm.CustomerContactDAO;
import cn.ekuma.epos.datalogic.define.dao.crm.CustomerPeopleDAO;
import cn.ekuma.epos.datalogic.define.dao.crm.concerns.ConcernsDAO;
import cn.ekuma.epos.datalogic.define.dao.crm.concerns.CustomerConcernsDAO;
import cn.ekuma.epos.datalogic.define.dao.crm.concerns.ProductCategoryConcernsDAO;
import cn.ekuma.epos.datalogic.define.dao.crm.concerns.ProductConcernsDAO;
import cn.ekuma.epos.datalogic.define.dao.crm.contract.ContractDAO;
import cn.ekuma.epos.datalogic.define.dao.crm.contract.ContractFollowDAO;
import cn.ekuma.epos.datalogic.define.dao.crm.contract.ContractProductDAO;
import cn.ekuma.epos.datalogic.define.dao.crm.service.TelephoneDAO;
import cn.ekuma.epos.datalogic.define.dao.crm.service.TelephoneFollowDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.CustomerAnalysisInfoDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.CustomerCategoryAnalysisInfoDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.CustomerCategoryTransactionDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.CustomerPaymentDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.CustomerStockCurrentInfoDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.CustomerTransactionDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.ERPAnalysisInfoDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.FinanceChargeAnysisInfoDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.FindOrdersInfoDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.FrontAnalysisInfoDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.FrontProductAnalysisInfoDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.OperationCustomerCategoryDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.OperationCustomerCategoryExtDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.OperationCustomerDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.OperationProductCategoryDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.OperationProductCategoryExtDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.OperationProductDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.OrderDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.OrderLineConsultInfoDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.OrderLineDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.OrderLine_VDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.OrderRelationDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.OrderRuleConfigDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.OrderStateDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.OrderTypeCategoryDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.OrderTypeCategoryExtDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.OrderTypeDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.PassengerFlowAnalysisInfoDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.PassengerFlowTransactionDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.ProductAnalysisDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.ProductCategoryAnalysisInfoDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.ProductCategoryTransactionDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.ProductLotNoStoreInfoDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.ProductTransactionDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.SharedLinkOrderDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.SharedOrderDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.TimeStoreDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.TimeStoreLineDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.TimeStoreLine_VDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.TimeStore_VDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.ordercalc.OrderCalcItemDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.ordercalc.OrderTypeCalcConfigDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.subject.SubjectCustomerCategoryDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.subject.SubjectCustomerDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.subject.SubjectDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.subject.SubjectInfoDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.subject.SubjectProductCategoryDAO;
import cn.ekuma.epos.datalogic.define.dao.erp.subject.SubjectProductDAO;
import cn.ekuma.epos.datalogic.define.dao.oa.AttenceDAO;
import cn.ekuma.epos.datalogic.define.dao.oa.ext.AttenceExtDAO;
import cn.ekuma.epos.datalogic.define.dao.sale.QuickProductExtDAO;
import cn.ekuma.epos.datalogic.define.dao.sale.TicketLine_VDAO;
import cn.ekuma.epos.datalogic.define.dao.sale.TicketsInfoDAO;

import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.serialize.DataParams;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.key.KeyBuilder;
import com.openbravo.data.loader.sentence.PreparedSentence;
import com.openbravo.data.loader.sentence.SentenceExec;
import com.openbravo.data.loader.serialize.serializer.write.SerializerWriteParams;
import com.openbravo.data.loader.table.TableDefinition;
import com.openbravo.data.loader.Transaction;
import com.openbravo.data.loader.query.QBFParameters;
import com.openbravo.bean.crm.contract.Contract;
import com.openbravo.bean.crm.contract.ContractFollow;
import com.openbravo.bean.crm.service.Telephone;
import com.openbravo.bean.crm.service.TelephoneFollow;
import com.openbravo.bean.erp.Order;
import com.openbravo.bean.erp.viewbean.OrderLineConsultInfo;
import com.openbravo.bean.erp.OperationProductCategory;
import com.openbravo.bean.erp.OrderRelation;
import com.openbravo.bean.erp.OrderState;
import com.openbravo.bean.erp.OrderType;
import com.openbravo.bean.BusinessPartner;
import com.openbravo.bean.PaymentsLine;
import com.openbravo.bean.Product;
import com.openbravo.bean.ProductCustomerCategoryPrice;
import com.openbravo.bean.ProductReserve;
import com.openbravo.bean.SharedProduct;
import com.openbravo.bean.erp.viewbean.CustomerCategoryTransaction;
import com.openbravo.bean.erp.viewbean.CustomerTransaction;
import com.openbravo.bean.erp.viewbean.FinanceChargeAnysisInfo;
import com.openbravo.bean.erp.viewbean.FindOrdersInfo;
import com.openbravo.bean.erp.viewbean.FrontProductAnalysisInfo;
import com.openbravo.bean.erp.viewbean.OrderLine_V;
import com.openbravo.bean.erp.viewbean.ProductAnalysis;
import com.openbravo.bean.erp.viewbean.ProductCategoryAnalysisInfo;
import com.openbravo.bean.erp.viewbean.ProductCategoryTransaction;
import com.openbravo.bean.erp.viewbean.ProductTransaction;
import com.openbravo.bean.erp.TimeStore;
import com.openbravo.bean.oa.Attence;
import com.openbravo.bean.sales.TicketLine_V;
import com.openbravo.bean.sales.TicketsInfo;

import java.util.*;

import cn.ekuma.epos.datalogic.define.dao.erp.OrderProcessConfigDAO;

/**
 *
 * @author Administrator
 */
public class DataLogicERP extends DataLogicSales implements I_DataLogicERP{

     TimeStore_VDAO  timeStore_VDAO ;
     OrderTypeCategoryDAO  orderTypeCategoryDAO;
     OrderTypeCategoryExtDAO orderTypeCategoryExtDAO;
     ServingDAO servingDAO;
     OrderTypeDAO orderTypeDAO;
     OrderLine_VDAO orderLine_VDAO;
     ProductTransactionDAO productTransactionDAO;
     SharedProductDAO sharedProductDAO;
     OrderStateDAO orderStateDAO;
     FindOrdersInfoDAO findOrdersInfoDAO;
     TimeStoreLine_VDAO timeStoreLine_VDAO;
     ERPAnalysisInfoDAO erpAnalysisInfoDAO;
     CustomerPaymentDAO customerPaymentDAO;
     ProductAnalysisDAO productAnalysisDAO;
     OrderLineConsultInfoDAO orderLineConsultInfoDAO;
     OrderRelationDAO orderRelationDAO;
     OrderDAO orderDAO;
     OrderLineDAO orderLineDAO;
     TimeStoreLineDAO timeStoreLineDAO;
     I_ProcessManager processManager;
     ProductReserveDAO productReserveDAO;
     TimeStoreDAO timeStoreDAO;
	private OperationProductCategoryDAO operationProductCategoryDAO;
	private OperationProductCategoryExtDAO operationProductCategoryExtDAO;
	private OperationProductDAO operationProductDAO;
    protected ProductStockLevelDAO productStockLevelDAO;
	private OperationCustomerCategoryDAO operationCustomerCategoryDAO;
	private OperationCustomerCategoryExtDAO operationCustomerCategoryExtDAO;
	private OperationCustomerDAO operationCustomerDAO;
	protected ProductLotNoStoreInfoDAO productLotNoStoreInfoDAO;
	protected SharedLinkOrderDAO sharedLinkOrderDAO;
	protected ProductCategoryAnalysisInfoDAO productCategoryAnalysisInfoDAO;
	protected ProductCategoryTransactionDAO productCategoryTransactionDAO;
	protected CustomerCategoryAnalysisInfoDAO customerCategoryAnalysisInfoDAO;
	protected CustomerCategoryTransactionDAO customerCategoryTransactionDAO;
	protected CustomerTransactionDAO customerTransactionDAO;
	protected CustomerAnalysisInfoDAO customerAnalysisInfoDAO;
    protected CustomerStockCurrentInfoDAO customerStockCurrentInfoDAO;
	protected FrontAnalysisInfoDAO frontAnalysisInfoDAO;
    protected PassengerFlowAnalysisInfoDAO passengerFlowAnalysisInfoDAO;
    protected PassengerFlowTransactionDAO passengerFlowTransactionDAO;
    protected OrderTypeCalcConfigDAO orderTypeCalcConfigDAO;
	private OrderCalcItemDAO orderCalcItemDAO;
	
	protected CustomerAddressDAO customerAddressDAO;
	protected CustomerContactDAO customerContactDAO;
	protected CustomerPeopleDAO customerPeopleDAO;
	protected TicketsInfoDAO ticketsInfoDAO;
	
	protected ConcernsDAO concernsDAO;
	protected CustomerConcernsDAO customerConcernsDAO;
	protected ProductCategoryConcernsDAO productCategoryConcernsDAO;
	protected ProductConcernsDAO productConcernsDAO;
	protected QuickProductExtDAO quickProductExtDAO;
	
	protected TelephoneDAO telephoneDAO;
	protected TelephoneFollowDAO telephoneFollowDAO;
	
	protected ContractDAO contractDAO;
	protected ContractFollowDAO contractFollowDAO; 
	protected SubjectDAO subjectDAO;
	protected SubjectCustomerCategoryDAO subjectCustomerCategoryDAO;
	protected SubjectCustomerDAO subjectCustomerDAO;
	protected SubjectInfoDAO subjectInfoDAO;
	protected SubjectProductCategoryDAO subjectProductCategoryDAO;
	protected SubjectProductDAO subjectProductDAO;
	
	protected OrderRuleConfigDAO orderRuleConfigDAO;
	
	protected ContractProductDAO contractProductDAO;

	TicketLine_VDAO ticketLine_VDAO;
	
	protected FinanceChargeAnysisInfoDAO financeChargeAnysisInfoDAO;
	
	protected OrderProcessConfigDAO orderProcessConfigDAO;
	private SharedOrderDAO shardOrderDAO;
	
	protected AttenceDAO attenceDAO;
	protected AttenceExtDAO attenceExtDAO;
	
	protected FrontProductAnalysisInfoDAO frontProductAnalysisInfoDAO;
	
    public DataLogicERP(EntityManager entityManager, I_ProcessManager processManager, Collection<I_CustomerDebtProcesser> customerDebtProcessers, Collection<I_ProductRecommend> productRecommends) {
    	super(entityManager, customerDebtProcessers, productRecommends);
    	this.processManager=processManager;
        timeStore_VDAO =new TimeStore_VDAO(s);
        addDaoToMap(timeStore_VDAO);

        orderTypeCategoryExtDAO=new  OrderTypeCategoryExtDAO(s);
        addDaoToMap(orderTypeCategoryExtDAO);

        orderTypeCategoryDAO=new OrderTypeCategoryDAO(s);
        addDaoToMap(orderTypeCategoryDAO);
        
        servingDAO=new ServingDAO(s);
        addDaoToMap(servingDAO);

        orderTypeDAO=new OrderTypeDAO(s);
        addDaoToMap(orderTypeDAO);

        orderLine_VDAO=new OrderLine_VDAO (s);
        addDaoToMap(orderLine_VDAO);

        productTransactionDAO=new ProductTransactionDAO(s);
        addDaoToMap(productTransactionDAO);

        sharedProductDAO=new SharedProductDAO(s);
        addDaoToMap(sharedProductDAO);

        orderStateDAO=new OrderStateDAO(s,userInfoDAO);
        addDaoToMap(orderStateDAO);
        

        findOrdersInfoDAO=new FindOrdersInfoDAO(s);
        addDaoToMap(findOrdersInfoDAO);

        orderRelationDAO=new OrderRelationDAO(s,findOrdersInfoDAO);
        addDaoToMap(orderRelationDAO);
        
        
        timeStoreLine_VDAO=new TimeStoreLine_VDAO(s);
        addDaoToMap(timeStoreLine_VDAO);

        erpAnalysisInfoDAO=new ERPAnalysisInfoDAO(s);
        addDaoToMap(erpAnalysisInfoDAO);

        customerPaymentDAO=new  CustomerPaymentDAO(s);
        addDaoToMap(customerPaymentDAO);

        productAnalysisDAO=new  ProductAnalysisDAO(s);
        addDaoToMap(productAnalysisDAO);

        orderLineConsultInfoDAO=new OrderLineConsultInfoDAO(s);
        addDaoToMap(orderLineConsultInfoDAO);

        orderDAO=new OrderDAO(s);
        addDaoToMap(orderDAO);

       orderLineDAO=new OrderLineDAO(s);
       addDaoToMap(orderLineDAO);

       timeStoreLineDAO=new TimeStoreLineDAO(s);
       addDaoToMap(timeStoreLineDAO);
        
       productReserveDAO=new ProductReserveDAO(s);
       addDaoToMap(productReserveDAO);
        
        timeStoreDAO=new TimeStoreDAO(s);
        addDaoToMap(timeStoreDAO);
        
        operationProductCategoryDAO=new OperationProductCategoryDAO(s);
        addDaoToMap(operationProductCategoryDAO);
        
        operationProductCategoryExtDAO=new OperationProductCategoryExtDAO(s);
        addDaoToMap(operationProductCategoryExtDAO);
        
        operationProductDAO=new OperationProductDAO(s,productDAO);
        addDaoToMap(operationProductDAO);
        
        productStockLevelDAO=new ProductStockLevelDAO(s,locationDAO);
        addDaoToMap(productStockLevelDAO);
        
        
        operationCustomerCategoryDAO=new OperationCustomerCategoryDAO(s);
        addDaoToMap(operationCustomerCategoryDAO);
        
        operationCustomerCategoryExtDAO=new OperationCustomerCategoryExtDAO(s);
        addDaoToMap(operationCustomerCategoryExtDAO);
        
        operationCustomerDAO=new OperationCustomerDAO(s,customerInfoDAO);
        addDaoToMap(operationCustomerDAO);
        
        productLotNoStoreInfoDAO=new ProductLotNoStoreInfoDAO(s);
        addDaoToMap(productLotNoStoreInfoDAO);
        
        sharedLinkOrderDAO=new SharedLinkOrderDAO(s);
        addDaoToMap(sharedLinkOrderDAO);
        
        productCategoryAnalysisInfoDAO=new ProductCategoryAnalysisInfoDAO(s);
        addDaoToMap(productCategoryAnalysisInfoDAO);
        
        productCategoryTransactionDAO=new ProductCategoryTransactionDAO(s);
        addDaoToMap(productCategoryTransactionDAO);
        
        customerCategoryAnalysisInfoDAO=new CustomerCategoryAnalysisInfoDAO(s);
        addDaoToMap(customerCategoryAnalysisInfoDAO);
        
        customerCategoryTransactionDAO=new CustomerCategoryTransactionDAO(s);
        addDaoToMap(customerCategoryTransactionDAO);
        
        customerTransactionDAO=new CustomerTransactionDAO(s);
         addDaoToMap(customerTransactionDAO);
         
    	customerAnalysisInfoDAO=new CustomerAnalysisInfoDAO(s);
    	addDaoToMap(customerAnalysisInfoDAO);
    	
    	customerStockCurrentInfoDAO=new CustomerStockCurrentInfoDAO(s);
    	addDaoToMap(customerStockCurrentInfoDAO);
    	
    	frontAnalysisInfoDAO=new FrontAnalysisInfoDAO(s);
    	addDaoToMap(frontAnalysisInfoDAO);
    	
    	passengerFlowAnalysisInfoDAO=new PassengerFlowAnalysisInfoDAO(s);
    	addDaoToMap(passengerFlowAnalysisInfoDAO);
    	
        passengerFlowTransactionDAO=new PassengerFlowTransactionDAO(s);
        addDaoToMap(passengerFlowTransactionDAO);
        
        orderTypeCalcConfigDAO=new OrderTypeCalcConfigDAO(s);
        addDaoToMap(orderTypeCalcConfigDAO);
        
        orderCalcItemDAO=new OrderCalcItemDAO(s);
        addDaoToMap(orderCalcItemDAO);
        
         customerAddressDAO=new CustomerAddressDAO(s);
         addDaoToMap(customerAddressDAO);
    	 customerContactDAO=new CustomerContactDAO(s);
    	 addDaoToMap(customerContactDAO);
    	 customerPeopleDAO=new CustomerPeopleDAO(s);
    	 addDaoToMap(customerPeopleDAO);
    	 ticketsInfoDAO=new TicketsInfoDAO(s);
    	 addDaoToMap(ticketsInfoDAO);
    	 
    	 concernsDAO=new ConcernsDAO(s);
    	 addDaoToMap(concernsDAO);
    	 customerConcernsDAO=new CustomerConcernsDAO(s);
    	 addDaoToMap(customerConcernsDAO);    
    	 productCategoryConcernsDAO=new ProductCategoryConcernsDAO(s);
    	 addDaoToMap(productCategoryConcernsDAO);
    	 productConcernsDAO=new ProductConcernsDAO(s);
    	 addDaoToMap(productConcernsDAO);
    	 
    	 quickProductExtDAO=new QuickProductExtDAO(s,quickProductDAO,product_VDAO);
    	 addDaoToMap(quickProductExtDAO);
    	 
    	 telephoneDAO=new TelephoneDAO(s);
    	 addDaoToMap(telephoneDAO);
    	 telephoneFollowDAO=new TelephoneFollowDAO(s);
    	 addDaoToMap(telephoneFollowDAO);
    	 
    	 contractDAO=new ContractDAO(s);
    	 addDaoToMap(contractDAO);
    	 contractFollowDAO=new ContractFollowDAO(s);
    	 addDaoToMap(contractFollowDAO);
    	 
    	 subjectDAO=new SubjectDAO(s);
    	 addDaoToMap(subjectDAO);
    	 
    	 subjectCustomerCategoryDAO=new SubjectCustomerCategoryDAO(s);
    	 addDaoToMap(subjectCustomerCategoryDAO);
    	 
    	 subjectCustomerDAO=new SubjectCustomerDAO(s);
    	 addDaoToMap(subjectCustomerDAO);
    	 
    	 subjectInfoDAO=new SubjectInfoDAO(s);
    	 addDaoToMap(subjectInfoDAO);
    	 
    	 subjectProductCategoryDAO=new SubjectProductCategoryDAO(s);
    	 addDaoToMap(subjectProductCategoryDAO);
    	 
    	 subjectProductDAO=new SubjectProductDAO(s);
    	 addDaoToMap(subjectProductDAO);
    	 
    	 orderRuleConfigDAO=new OrderRuleConfigDAO(s);
    	 addDaoToMap(orderRuleConfigDAO);
    	 
    	 ticketLine_VDAO=new TicketLine_VDAO(s);
    	  addDaoToMap(ticketLine_VDAO);
    	  
    	  contractProductDAO=new ContractProductDAO(s,this.productDAO);
    	  addDaoToMap(contractProductDAO);
    	  
    	  
    	 financeChargeAnysisInfoDAO=new FinanceChargeAnysisInfoDAO(s);
    	 addDaoToMap(financeChargeAnysisInfoDAO);
    	 
    	 orderProcessConfigDAO=new OrderProcessConfigDAO(s);
    	 addDaoToMap(orderProcessConfigDAO);
    	 
    	 shardOrderDAO=new SharedOrderDAO(s);
    	 
    	 attenceDAO=new AttenceDAO(s);
    	 addDaoToMap(attenceDAO);
    	 
    	 attenceExtDAO=new AttenceExtDAO(s,userInfoDAO,attenceDAO);
    	 addDaoToMap(attenceExtDAO);
    	 
    	 frontProductAnalysisInfoDAO=new FrontProductAnalysisInfoDAO(s);
    	 addDaoToMap(frontProductAnalysisInfoDAO);
    }




    
    @Override
    public OrderType findOrderTypeById(String id) throws BasicException {
        return orderTypeDAO.findOrderTypeById(id);
    }

    @Override
    public List<OrderRelation> listOrderRelationInfoByOrder(String id) throws BasicException {
        return orderRelationDAO.listOrderRelationInfoByOrder(id);
    }

    @Override
    public List<OrderRelation> listOrderRelationInfoByRefOrder(String id) throws BasicException {
        return orderRelationDAO.listOrderRelationInfoByRefOrder(id);
     }


    @Override
    public List<OrderState> listOrderStateByOrder(final String id) throws BasicException {
        return this.listByParent(OrderState.class, new I_ParentNode(){
			@Override
			public IKeyed getParentKey() {
				return KeyBuilder.getKey(id);
			}
			@Override
			public Class getParentClass() {
				return Order.class;
			}
        	
        });
    }

    @Override
    public Integer getNextOrderIndex() throws BasicException {
        return (Integer) s.getDialect().getSequenceSentence(s, "ORDERSNUM").find();
    }

    @Override
    public Integer getNextOrderRefundIndex() throws BasicException {
        return (Integer) s.getDialect().getSequenceSentence(s, "ORDERSREFUNDNUM").find();
    }

    @Override
    public List listBuildedTimeStore() throws BasicException {
        return timeStore_VDAO.listBuildedTimeStore();
    }

     @Override
    public void saveOrder(Order order) throws BasicException {
    	 processManager.saveOrder(this, order);
    }

    @Override
    public Order loadOrder(String orderid) throws BasicException {
        return processManager.loadOrder(this, orderid);
    }

    @Override
    public void deleteOrder(final Order order) throws BasicException {
    	processManager.deleteOrder(this, order);
    }

    @Override
    public void createTimeStoreLines(final TimeStore timeStore) throws BasicException {
        if (timeStore.getProductCatRef() != null) {
            SentenceExec timeStoreLinesinsert = new PreparedSentence(s, "INSERT INTO TIMESTORELINES (ID,TIMESTOREID, PRODUCT, ATTRIBUTESETINSTANCE_ID, UNITS) SELECT P.ID,?,S.PRODUCT,S.ATTRIBUTESETINSTANCE_ID,S.UNITS  FROM STOCKCURRENT S , PRODUCTS P WHERE S.PRODUCT=P.ID AND S.LOCATION=? AND P.CATEGORY=?  ", SerializerWriteParams.INSTANCE);
            timeStoreLinesinsert.exec(new DataParams() {
                public void writeValues() throws BasicException {
                    setString(1, timeStore.getID());
                    setString(2, timeStore.getLocationRef());
                    setString(3, timeStore.getProductCatRef());
                }
            });
        } else {
            SentenceExec timeStoreLinesinsert = new PreparedSentence(s, "INSERT INTO TIMESTORELINES (ID,TIMESTOREID, PRODUCT, ATTRIBUTESETINSTANCE_ID, UNITS) SELECT P.ID,?,S.PRODUCT,S.ATTRIBUTESETINSTANCE_ID,S.UNITS  FROM STOCKCURRENT S , PRODUCTS P WHERE S.PRODUCT=P.ID AND S.LOCATION=? ", SerializerWriteParams.INSTANCE);
            timeStoreLinesinsert.exec(new DataParams() {
                public void writeValues() throws BasicException {
                    setString(1, timeStore.getID());
                    setString(2, timeStore.getLocationRef());
                }
            });
        }
    }


    @Override
    public void deleteTimeStoreLines(TimeStore timeStore) throws BasicException {
        timeStoreLineDAO.deleteTimeStoreLines(timeStore.getID());
    }

    @Override
    public Double getProductUnitsInOrder(final String orderId, final String productId, final String attsetinst) throws BasicException {
        return orderLineConsultInfoDAO.getProductUnitsInOrder(orderId, productId, attsetinst);
    }

    @Override
    public Double getProductUnitsInTimeStore(final String timeStoreId, final String productId, final String attsetinst) throws BasicException {
        return orderLineConsultInfoDAO.getProductUnitsInTimeStore(timeStoreId, productId, attsetinst);
    }

    @Override
    public Double getProductUnitsInRealStore(final String location, final String productId, final String attsetinst) throws BasicException {
         return orderLineConsultInfoDAO.getProductUnitsInRealStore(location, productId, attsetinst);
    }


    @Override
    public List<OrderLineConsultInfo> listConsultInfoByOrder(String orderId) throws BasicException {
        return orderLineConsultInfoDAO.listConsultInfoByOrder(orderId);    }

    @Override
    public List<OrderLineConsultInfo> listConsultInfoByRealStore(String locationId) throws BasicException {
        return orderLineConsultInfoDAO.listConsultInfoByRealStore(locationId);
    }

    @Override
    public List<OrderLineConsultInfo> listConsultInfoByTimeStore(String timeStoreId) throws BasicException {
        return orderLineConsultInfoDAO.listConsultInfoByTimeStore(timeStoreId);    }

    @Override
    public List<OrderLineConsultInfo> listConsultInfoByRealStore(final String locationRef, final String customerId) throws BasicException {
        return orderLineConsultInfoDAO.listConsultInfoByRealStore(locationRef, customerId);
    }

    public List<ProductTransaction> productTransactionListQBF(Object filter) throws BasicException{
        return productTransactionDAO.productTransactionListQBF(filter);
    }

    public  List<ProductTransaction> productPOSTransactionListQBF(Object filter) throws BasicException{
        return productTransactionDAO.productPOSTransactionListQBF(filter);
    }

    public List<OrderLine_V> productTransactionDialyListQBF(Object filter)throws BasicException{
        return orderLine_VDAO.productTransactionDialyListQBF(filter);
      }

    public  List<OrderLine_V> productPOSTransactionDialyListQBF(Object filter)throws BasicException {
        return orderLine_VDAO.productPOSTransactionDialyListQBF(filter);
     }


    public void saveSharedProduct(final SharedProduct p) throws BasicException {
        sharedProductDAO.insert(p);
    }

    public List<ProductCustomerCategoryPrice> list(String productId) throws BasicException {
        return productCustomerCategoryPriceDAO.list(new I_ParentNode(){
            @Override
            public IKeyed getParentKey() {
                return KeyBuilder.getKey(productId);
            }

            @Override
            public Class getParentClass() {
                return Product.class;
            }
        });
    }

    public I_ProcessManager getOrderProcessManager() {
       return processManager;
    }

	@Override
	public ProductReserve getProductReserveByCode(String sCode)
			throws BasicException {
		return productReserveDAO.getProductReserveByCode(sCode);
	}

	@Override
	public List<ProductReserve> listProductReserveBySimilarCode(String code)
			throws BasicException {
		return productReserveDAO.listProductReserveBySimilarCode(code);
	}

	@Override
	public List<OperationProductCategory> listOperationProductCategoryByProduct(
			String productId) throws BasicException {
		return operationProductCategoryDAO.listOperationProductCategoryByProduct(productId);
	}

	@Override
	public List<FindOrdersInfo> listOrderInfoByAnlysis(Object filter)
			throws BasicException {
		return this.findOrdersInfoDAO.listOrderInfoByAnlysis(filter);
	}

	@Override
	public List<Product> listByOperationCategory(String operationCategoryId)
			throws BasicException {
		return productDAO.listByOperationCategory(operationCategoryId);
	}

	@Override
	public List<Product> listProductByErrorPrice() throws BasicException {
		return productDAO.listProductByErrorPrice();
	}

	@Override
	public List<Product> listProductByBOM() throws BasicException {
		return productDAO.listProductByBOM();
	}

	@Override
	public List<Product> listProductByProfits(double form, double to)
			throws BasicException {
		return productDAO.listProductByProfits(form, to);
	}

	@Override
	public Order loadLinkOrder(String id) throws BasicException {
		return sharedLinkOrderDAO.getSharedOrder(id);
	}

	@Override
	public List<ProductCategoryTransaction> productCategoryTransactionListQBF(
			Object filter) throws BasicException {
		return productCategoryTransactionDAO.productCategoryTransactionListQBF(filter);
	}

	@Override
	public List<ProductCategoryTransaction> productCategoryPOSTransactionListQBF(
			Object filter) throws BasicException {
		return productCategoryTransactionDAO.productCategoryPOSTransactionListQBF(filter);
	}

	@Override
	public List<CustomerCategoryTransaction> customerCategoryTransactionListQBF(
			Object[] filter1) throws BasicException {
		return customerCategoryTransactionDAO.customerCategoryTransactionListQBF(filter1);
	}

	@Override
	public List<CustomerCategoryTransaction> customerCategoryPOSTransactionListQBF(
			Object[] filter1) throws BasicException {
		return customerCategoryTransactionDAO.customerCategoryPOSTransactionListQBF(filter1);
	}

	@Override
	public List<BusinessPartner> listCustomerByOperationCategory(String id)
			throws BasicException {
		return customerDAO.listCustomerByOperationCategory(id);
	}

	@Override
	public List<CustomerTransaction> customerTransactionListQBF(
			QBFParameters transactionFilter) throws BasicException {
		return customerTransactionDAO.customerTransactionListQBF(transactionFilter);
	}

	@Override
	public List<CustomerTransaction> customerPOSTransactionListQBF(
			QBFParameters transactionFilter) throws BasicException {
		return customerTransactionDAO.customerPOSTransactionListQBF(transactionFilter);
	}
	
	
	public List<FindOrdersInfo> listShardOrder(Object filter) throws BasicException{
		return this.findOrdersInfoDAO.listShardOrder(filter);
	}
	
	public List<TicketsInfo> listByTicketId(String id) throws BasicException {
		return  ticketsInfoDAO.listByTicketId(id);
	}
	
	public void updateTelephone(final Telephone parent,final TelephoneFollow follow)throws BasicException {
		Transaction t = new Transaction(s) {
            public Object transact() throws BasicException {
            	telephoneFollowDAO.update(follow);
            	StateObjectHelper.updateStateObject(parent, follow);
            	telephoneDAO.update(parent);	
				return null;
            	
            }
		};
		t.execute();
	}

	@Override
	public void updateContract(final Contract parent, final ContractFollow follow)
			throws BasicException {
		Transaction t = new Transaction(s) {
            public Object transact() throws BasicException {
            	contractFollowDAO.update(follow);
            	StateObjectHelper.updateStateObject(parent, follow);
            	contractDAO.update(parent);	
				return null;
            }
		};
		t.execute();
	}

	@Override
	public List<ProductAnalysis> listProductAnalysisByCustomer(String location,
			String customer) throws BasicException {
		return productAnalysisDAO.listProductAnalysisByCustomer(location, customer);
	}

	@Override
	public List<ProductAnalysis> listProductAnalysisByProductCurDate(
			Date startDate, Date endDate) throws BasicException {	
		return productAnalysisDAO.listProductAnalysisByProductCurDate(startDate, endDate);
	}

	@Override
	public Double findCustomerCategoryWholesalePrice(String productId,
			String categoryid) throws BasicException {
		return productCustomerCategoryPriceDAO.findCustomerCategoryWholesalePrice(productId, categoryid);
	}

	@Override
	public HashMap findOrderRulePropByNameAndOrderType(String orderTypeId,
			String ruleName) throws BasicException {
		return orderRuleConfigDAO.findOrderRulePropByNameAndOrderType( orderTypeId,
				 ruleName);
	}
	

	@Override
	public List<String> findOrderSuperedRuleByOrderType(String orderTypeId)
			throws BasicException {
		return orderRuleConfigDAO.findOrderSuperedRuleByOrderType(orderTypeId);
	}

	@Override
	public List<TicketLine_V> listSaleManTicketLine(Object[] beforeFilterParas)
			throws BasicException {
		return ticketLine_VDAO.listSaleManTicketLine(beforeFilterParas);
		
	}

	@Override
	public List<PaymentsLine> listPayments(FinanceChargeAnysisInfo info,
			Object filter) throws BasicException {	
		return financeChargeAnysisInfoDAO.listPayments(info, filter);
	}


	@Override
	public HashMap findOrderProcessPropByNameAndOrderType(String orderTypeId,
			String processName) throws BasicException {
		return this.orderProcessConfigDAO.findOrderProcessPropByNameAndOrderType(orderTypeId, processName);
	}

	public List<String> findOrderSuperedProcessByOrderType(String orderTypeId)
			throws BasicException {
		return orderProcessConfigDAO.findOrderSuperedRuleByOrderType(orderTypeId);
	}

	@Override
	public List<ProductCategoryAnalysisInfo> listPosCategoryAnalysisInfo(
			Object filter) throws BasicException {
		return productCategoryAnalysisInfoDAO.listPosCategoryAnalysisInfo(filter);
	}
	
    @Override
    public Order getSharedOrder(String Id) throws BasicException {
    	return shardOrderDAO.getSharedOrder(Id);
    }


    @Override
    public void updateOrderState(String id, String afterState) throws BasicException {
        orderDAO.updateOrderState(id,afterState);
    }

    @Override
    public void updateOrderDebt(String id, double cash) throws BasicException {
        orderDAO.updateOrderDebt(id,cash);
    }

    @Override
	public List<FindOrdersInfo> listOrderInfo(Object filter)
			throws BasicException {

		return findOrdersInfoDAO.list(filter);
	}

	@Override
	public Attence attence(String userId, String attenceName)
			throws BasicException {
		Attence obj=new Attence();
		obj.setCreateDate(new Date());
		obj.setUserId(userId);
		obj.setAttenceName(attenceName);
		insert(obj);
		return obj;
	}
	
	
	public void doBackDb() throws BasicException{
		/**ImpExpManager manager=new ImpExpManager();
		manager.regeditTables(getImpExpTableList(TABLE_All));
		manager.doExport(CSVEngine.PROPERTY_prefix, null, null);
         **/
	}

	@Override
	public void restoreDb() throws BasicException {
		/**ImpExpManager manager=new ImpExpManager();
		manager.regeditTables(getImpExpTableList(TABLE_All));
		manager.doImport(CSVEngine.PROPERTY_prefix);
         **/
	}


	public List<TableDefinition> getImpExpTableList(int type){
         ArrayList retList=new ArrayList();
        /** switch(type){
		    case TABLE_Base:
		    	retList.addAll(getImpExpBaseTableList());
		    	break;
		    case TABLE_Erp:
		    	retList.addAll(getImpExpERPTableList());
		        break;
		    case TABLE_Crm:
		    	retList.addAll(getImpExpCRMTableList());
		    	 break;
		    case TABLE_All:
		    	retList.addAll(getImpExpBaseTableList());
		    	retList.addAll(getImpExpCRMTableList());
		    	retList.addAll(getImpExpERPTableList());
		        break;
		 }**/
		return retList;
	}
    /**
	public List<TableDefinition> getImpExpBaseTableList(){
		 ArrayList retList=new ArrayList();
		    retList.add(this.locationDAO.getTableDefinition());
			retList.add(this.userDAO.getTableDefinition());
			retList.add(this.floorDAO.getTableDefinition());
			retList.add(this.placeDAO.getTableDefinition());
			
			retList.add(this.locationLayoutDAO.getTableDefinition());
			
			
			retList.add(this.attributeDAO.getTableDefinition());
			retList.add(this.attributeSetDAO.getTableDefinition());
			retList.add(this.attributeValueDAO.getTableDefinition());
			retList.add(this.attributeSetInstanceDAO.getTableDefinition());
			retList.add(this.attributeUseDAO.getTableDefinition());
			
			
			retList.add(this.taxCategoryDAO.getTableDefinition());
			retList.add(this.taxCustCategoryDAO.getTableDefinition());
			retList.add(this.taxDAO.getTableDefinition());
			
			
			retList.add(this.customerCategoryDAO.getTableDefinition());
			retList.add(this.customerDAO.getTableDefinition());
			retList.add(this.customerPeopleDAO.getTableDefinition());
			retList.add(this.customerAddressDAO.getTableDefinition());
			retList.add(this.customerContactDAO.getTableDefinition());
			retList.add(this.customerStoreValueCardDAO.getTableDefinition());
			
	
			retList.add(this.productCategoryDAO.getTableDefinition());
			retList.add(this.productDAO.getTableDefinition());
			retList.add(this.productCodeDAO.getTableDefinition());
			retList.add(this.productAuxiliarDAO.getTableDefinition());
			retList.add(this.productAttributeValuePriceDAO.getTableDefinition());
			retList.add(this.productCustomerCategoryPriceDAO.getTableDefinition());
			retList.add(this.productLocationStateDAO.getTableDefinition());
			retList.add(this.productPriceDAO.getTableDefinition());
			retList.add(this.productScoreDAO.getTableDefinition());
			retList.add(this.quickProductDAO.getTableDefinition());
			retList.add(this.bomProductDAO.getTableDefinition());
			retList.add(this.productStockLevelDAO.getTableDefinition());
			
			retList.add(this.voucherDAO.getTableDefinition());
			
			retList.add(this.productPrefPriceDAO.getTableDefinition());
			
			

		 return retList;
	}
	

	public List<TableDefinition> getImpExpCRMTableList(){
		  ArrayList retList=new ArrayList();
		//CRM
			retList.add(this.contractDAO.getTableDefinition());
			retList.add(this.contractFollowDAO.getTableDefinition());
			retList.add(this.contractProductDAO.getTableDefinition());
			
			retList.add(this.telephoneDAO.getTableDefinition());
			retList.add(this.telephoneFollowDAO.getTableDefinition());
			
			retList.add(this.operationProductCategoryDAO.getTableDefinition());
			retList.add(this.operationProductDAO.getTableDefinition());
			retList.add(this.operationCustomerCategoryDAO.getTableDefinition());
			retList.add(this.operationCustomerDAO.getTableDefinition());
			

			
			retList.add(this.subjectDAO.getTableDefinition());
			retList.add(this.subjectCustomerCategoryDAO.getTableDefinition());
			retList.add(this.subjectCustomerDAO.getTableDefinition());
			retList.add(this.subjectProductCategoryDAO.getTableDefinition());
			retList.add(this.subjectProductDAO.getTableDefinition());
			
			retList.add(this.concernsDAO.getTableDefinition());
			retList.add(this.customerConcernsDAO.getTableDefinition());
			retList.add(this.productCategoryConcernsDAO.getTableDefinition());
			retList.add(this.productConcernsDAO.getTableDefinition());
			
			retList.add(this.attenceDAO.getTableDefinition());
		  
		  return retList;
	}
		 	

	public List<TableDefinition> getImpExpERPTableList(){
		  ArrayList retList=new ArrayList();

		  retList.add(this.productReserveDAO.getTableDefinition());
		//erp
			retList.add(this.orderTypeCategoryDAO.getTableDefinition());
			retList.add(this.orderTypeDAO.getTableDefinition());
			retList.add(this.orderRuleConfigDAO.getTableDefinition());
		    retList.add(this.orderProcessConfigDAO.getTableDefinition());
		  
		  
		  retList.add(this.closeCashDAO.getTableDefinition());
		  retList.add(this.receiptDAO.getTableDefinition());
		  retList.add(this.paymentDAO.getTableDefinition());
		  retList.add(this.taxLineDAO.getTableDefinition());
		  
		  retList.add(this.stockCurrentDAO.getTableDefinition());
		  retList.add(this.stockDiaryDAO.getTableDefinition());
		  retList.add(this.lotNoStockCurrentDAO.getTableDefinition());
		  retList.add(this.locationLayoutCurrentDAO.getTableDefinition());
		  
		  retList.add(this.customerStorckCurrentDAO.getTableDefinition());
		  retList.add(this.customerStoreValueCardDiaryDAO.getTableDefinition());
		  retList.add(this.customerScoreDiaryDAO.getTableDefinition());
		  retList.add(this.customerProductDAO.getTableDefinition());
		  
		  retList.add(this.voucherDiaryDAO.getTableDefinition());
		  
		  retList.add(this.ticketDAO.getTableDefinition());
		  retList.add(this.ticketLineDAO.getTableDefinition());
		  retList.add(this.closeCashDAO.getTableDefinition());
		  

		  retList.add(this.orderDAO.getTableDefinition());
		  retList.add(this.orderLineDAO.getTableDefinition());
		  retList.add(this.orderStateDAO.getTableDefinition());
		  retList.add(this.orderRelationDAO.getTableDefinition());
		  retList.add(this.orderCalcItemDAO.getTableDefinition());
		  
		  retList.add(this.timeStoreDAO.getTableDefinition());
		  retList.add(this.timeStoreLineDAO.getTableDefinition());

		  return retList;
	}
	

	public  List<Class> getSyncClient(){
		List<Class> retList=new ArrayList();
		
		return retList;
	}
	
	
	public  List<Class> getSyncService(){
		List<Class> retList=new ArrayList();
		
		  retList.add(locationDAO.getSuportClass());
			retList.add(this.userDAO.getSuportClass());
			retList.add(this.floorDAO.getSuportClass());
			retList.add(this.placeDAO.getSuportClass());
			
			retList.add(this.locationLayoutDAO.getSuportClass());
			
			
			retList.add(this.attributeDAO.getSuportClass());
			retList.add(this.attributeSetDAO.getSuportClass());
			retList.add(this.attributeValueDAO.getSuportClass());
			retList.add(this.attributeSetInstanceDAO.getSuportClass());
			retList.add(this.attributeUseDAO.getSuportClass());
			
			
			retList.add(this.taxCategoryDAO.getSuportClass());
			retList.add(this.taxCustCategoryDAO.getSuportClass());
			retList.add(this.taxDAO.getSuportClass());
			
			
			retList.add(this.customerCategoryDAO.getSuportClass());
			retList.add(this.customerDAO.getSuportClass());
			retList.add(this.customerPeopleDAO.getSuportClass());
			retList.add(this.customerAddressDAO.getSuportClass());
			retList.add(this.customerContactDAO.getSuportClass());
			retList.add(this.customerStoreValueCardDAO.getSuportClass());
			
	
			retList.add(this.productCategoryDAO.getSuportClass());
			retList.add(this.productDAO.getSuportClass());
			retList.add(this.productCodeDAO.getSuportClass());
			retList.add(this.productAuxiliarDAO.getSuportClass());
			retList.add(this.productAttributeValuePriceDAO.getSuportClass());
			retList.add(this.productCustomerCategoryPriceDAO.getSuportClass());
			retList.add(this.productLocationStateDAO.getSuportClass());
			retList.add(this.productPriceDAO.getSuportClass());
			retList.add(this.productScoreDAO.getSuportClass());
			retList.add(this.quickProductDAO.getSuportClass());
			retList.add(this.bomProductDAO.getSuportClass());
			retList.add(this.productStockLevelDAO.getSuportClass());
			
			retList.add(this.voucherDAO.getSuportClass());
			
			retList.add(this.productPrefPriceDAO.getSuportClass());
		return retList;
	}**/

    public void doExportTableDateDb(List<TableDefinition> exportTales,Date start,Date end) throws BasicException{
       /* ImpExpManager manager=new ImpExpManager();
        manager.regeditTables(exportTales);
        manager.doExport(CSVEngine.PROPERTY_prefix, start, end);*/
    }


    @Override
	public List<FrontProductAnalysisInfo> listFrontProductAnalysisByCustomer(String location, String customer,
			Date startTime, Date endTime) throws BasicException {
		return frontProductAnalysisInfoDAO.listFrontProductAnalysisByCustomer(location, customer, startTime, endTime);
	}

	@Override
	public List<FrontProductAnalysisInfo> listFrontProductAnalysisByNewProducts(String location, Date newProductStartTime,
			Date newProductEndTime, Date startTime, Date endTime) throws BasicException {
		return frontProductAnalysisInfoDAO.listFrontProductAnalysisByNewProducts(location, newProductStartTime, newProductEndTime, startTime, endTime);
	}



	@Override
	public List<FrontProductAnalysisInfo> listFrontProductAnalysisByProductSimilarCode(String location, String product,
			Date startTime, Date endTime) throws BasicException {
		return frontProductAnalysisInfoDAO.listFrontProductAnalysisByProductSimilarCode(location, product, startTime, endTime);
	}

	
	
	
}
